package com.zhaoxianglong.priciple;

import org.junit.Test;

/**
 * @program: design-learning
 * @description: 里氏替换原则
 * @author: zhaoxianglong
 * @create: 2021-03-17 14:58
 **/
public class Liskov {

    @Test
    public void test1(){
        Test1 test1 = new Test1();
        System.out.println(test1.func1(8,6));
        Test2 test2 = new Test2();
        System.out.println(test2.func1(8,6));
    }

    @Test
    public void test2(){
        Test4 test1 = new Test4();
        System.out.println(test1.func1(8,6));
        Test5 test2 = new Test5();
        System.out.println(test2.func1(8,6));
    }

    @Test
    public void test3(){
        Test6 test6 = new Test6();
        test6.func1(8,6);
        Test7 test7 = new Test7();
        test7.func3(8,6);
    }
}

class Test1{
    public int func1(int a , int b){
        return a-b;
    }
}

class Test2 extends Test1{
    @Override
    public int func1(int a , int b){
        return a+b;
    }
    public int func2(int a , int b){
        return a*b;
    }
}

class Test3{
    public int func1(int a , int b){
        return a-b;
    }
}
class Test4 extends Test3{

}

class Test5 extends Test3{

    public int func2(int a , int b){
        return a*b;
    }
}

class Base{
}
class Test6 extends Base{
    public int func1(int a , int b){
        return a-b;
    }

}
class Test7 extends Base{
     private Test6 test6 = new Test6();

    public int func3(int a , int b){
        return test6.func1(a, b);
    }
}
